import { Injectable } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class GoodsService {
  del(id: any): any {
    const url = "/mdse/del?spuIds=" + id;
    return this.http.post(url);
  }

  constructor(private http: _HttpClient) { }

  queryList(paging: any): Observable<any> {
    const url = "/mdse/querySpuList?pageStart=1&pageSize=25";
    return this.http.get(url); 
  }

  // 新建
  createOrEdit(data: any): Observable<any> {
    const url = "/mdse/save";
    return this.http.post(url, data);
  }

  // 设置退换货规则
  setSpuRela(spuId: any, ruleId: any): Observable<any> {
    const url = "/aftersaleConf/setSpuRela/" + ruleId;
    return this.http.post(url, spuId);
  }

  queryCategoryList(): Observable<any> {
    const url = "/category/list?pageStart=1&pageSize=25";
    return this.http.get(url); 
  }

  // 上下架 1上架，2下架
  upOrDownGoods(whichOne: any, ids: any): Observable<any> {
    const url = "/mdse/status/" + whichOne;
    return this.http.post(url, ids); 
  }

  // 查询详情
  getSpuDetail(spuId: any): Observable<any> {
    const url = "/mdse/spuDetailById/" + spuId;
    return this.http.get(url);
  }

  // 查询spu退换货规则
  getSpuaftersaleConf(spuId: any): Observable<any> {
    const url = "/aftersaleConf/bySpuId/" + spuId;
    return this.http.post(url);
  }

  // 批量设置sku会员价和积分
  batchSetMemberPriceAndIntegral(data: any): Observable<any> {
    const url = "/integralMdse/savebatch";
    return this.http.post(url, data);
  }

  // 设置sku会员价和积分
  setMemberPriceAndIntegral(data: any): Observable<any> {
    const url = "/integralMdse/save";
    return this.http.post(url, data);
  }
}
